package com.itrencai.d8_stream;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

//初步体验stream流的方便和快速
//找出姓张并且名字有三个字的人，过滤操作
public class TiYan {
    public static void main(String[] args) {
        List<String> names=new ArrayList<>();
        Collections.addAll(names,"张三丰","张无忌","周芷若","赵敏","张强");
        System.out.println(names);
/*        //1.从集合中找出姓张的放到新集合
        List<String> zhangList=new ArrayList<>();
        for (String name : names) {
            if(name.startsWith("张")) {
                zhangList.add(name);
            }
        }
        System.out.println(zhangList);
        //2.找出名称长度是3的姓名
        List<String> zhangthreeList=new ArrayList<>();
        for (String name : zhangList) {
            if(name.length()==3) {
                zhangthreeList.add(name);
            }
        }
        System.out.println(zhangthreeList);*/

        //使用stream实现,可链式
        names.stream().filter(s->s.startsWith("张")).filter(s->s.length()==3).forEach(s-> System.out.println(s));








    }

}
